/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"34F05782-17BE-40AB-A047-189284C056F6",variableType:8}
 */
var T_ganancias_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B56D86B5-A0C5-4CD5-A86C-624023FC4690",variableType:4}
 */
var entero = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"89EA69C6-2BD4-4C83-A337-2190C1E96C84",variableType:8}
 */
var f_iva_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4AD6FCAE-4FDF-489E-ADF7-075F20428829",variableType:8}
 */
var f_iva_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7FF138F9-9BB9-49E9-9F16-368291D15EC6",variableType:8}
 */
var f_iva_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"58BD5D9C-EA64-49C0-A56E-210E9DA3C6CB",variableType:8}
 */
var f_iva_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D9E9EBDC-AA71-409F-9D4D-DD2E4C2D41D4",variableType:8}
 */
var f_neto_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7A50C050-9E4E-4299-AE8E-C2BE65A27FAB",variableType:8}
 */
var f_neto_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0DBDC2A9-554F-496F-ADAC-6A3378DBF6AD",variableType:8}
 */
var f_neto_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FAF1A14F-CFB2-4A01-937D-AC3304CD983B",variableType:8}
 */
var f_neto_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E49AE08E-B86B-4F08-AE68-E4B70CCEE5B3",variableType:4}
 */
var lineas_hoja = 30;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C146AD64-7E7E-4A43-A9F4-12E43BEDEA8B",variableType:4}
 */
var nro_pag = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EF1B941E-85C2-467E-95DD-3EB6490C8373",variableType:8}
 */
var porc_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"22C749AD-9B91-4F43-92A6-16D8B5D1B1B7",variableType:8}
 */
var porc_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"46F460AC-473E-483D-8A3E-D57CF3646CB3",variableType:8}
 */
var porc_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C397E244-2E74-4C24-9415-5F7E8447D2E8",variableType:8}
 */
var porc_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9B929E50-CE67-48D2-8C27-D5E477CE3D97",variableType:8}
 */
var T_ib_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"F7C72A0C-B5B8-4BC5-8A90-ED69C40DAA46",variableType:8}
 */
var T_importe = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3D9A0680-7814-4A32-86DF-064AE660387C",variableType:8}
 */
var T_itc = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"6F77909F-7EAE-49FF-ACB6-C4AA0C41B764",variableType:8}
 */
var T_iva = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"34A9AC32-3BCA-4926-A14B-D0930DDD704B",variableType:8}
 */
var T_iva_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C846D601-12D3-4782-B4CA-B7F064836381",variableType:8}
 */
var T_neto = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"50F5EE14-E3EF-4EB6-8DE0-AAB676DA3F8A",variableType:8}
 */
var T_neto_exento = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"07DDADD7-575B-442E-AB7E-37880879D542",variableType:8}
 */
var T_neto_monotrib = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3FF8C7A2-4ADE-4454-ACE0-06C996B07DAA",variableType:8}
 */
var T_neto_no_grav = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D74CDED2-C666-4401-8E09-085CB613C532",variableType:8}
 */
var T_neto_no_gravado = null;

/**
 *
 * @properties={typeid:24,uuid:"886FA72C-4525-4DAB-8D94-11F9BB3B590F"}
 */
function calcular_totales()
{	
	
	var tabla_totales = databaseManager.createEmptyDataSet(10,4)
	
	for ( var k = 0 ; k < 10 ; k ++ )
	{
		tabla_totales.setValue(k, 1, 0.00);
		tabla_totales.setValue(k, 2, 0.00);
		tabla_totales.setValue(k, 3, 0.00);
		tabla_totales.setValue(k, 4, 0.00);
	}
	
	T_neto				= 0
	T_iva				= 0
	T_importe			= 0
	T_iva_percep		= 0
	T_itc				= 0
	T_neto_no_gravado	= 0
	T_ib_percep			= 0
	T_neto_monotrib		= 0
	T_neto_exento		= 0
	T_neto_no_grav		= 0
	T_ganancias_percep	= 0
	
	controller.sort("fecha_mov asc, cod_mov asc, letra asc, sucursal asc, nro_factura asc")

	// recorre foundset
	//var hoja_desde = globals.ghoja_desde_diario
	var $ctos = databaseManager.getFoundSetCount(foundset)
	for ( var i = 1 ; i <= $ctos; i++ )
	{
		controller.setSelectedIndex(i)
		
		neto_impresion	= 0
		iva_impresion	= 0
		porc_impresion	= null
		if (neto != 0 && neto != null)
		{
			neto_impresion	= neto_signo
			iva_impresion	= iva_signo
			porc_impresion	= ctacte_pr_to_tasa_iva_porc.porc_impresion;
		}
		if (neto_2 != 0 && neto_2 != null)
		{
			neto_impresion	+= neto_2_signo
			iva_impresion	+= iva_2_signo
			if (ctacte_pr_to_tasa_iva_porc_2.porc_impresion != null && ctacte_pr_to_tasa_iva_porc_2.porc_impresion != ' ')
				porc_impresion = porc_impresion + '-' + ctacte_pr_to_tasa_iva_porc_2.porc_impresion;
		}
		if (neto_3 != 0 && neto_3 != null)
		{
			neto_impresion	+= neto_3_signo
			iva_impresion	+= iva_3_signo
			if (ctacte_pr_to_tasa_iva_porc_3.porc_impresion != null && ctacte_pr_to_tasa_iva_porc_3.porc_impresion != ' ')
				porc_impresion = porc_impresion + '-' + ctacte_pr_to_tasa_iva_porc_3.porc_impresion;
		}

		T_neto				+= neto_impresion
		T_iva				+= iva_impresion
		T_importe			+= importe_signo
		T_iva_percep		+= iva_percep_signo
		T_itc				+= itc_signo
		T_neto_no_gravado 	+= neto_no_gravado_signo  
		T_ib_percep			+= ib_percep_signo
		T_ganancias_percep	+= ganancias_percep_signo
		
		if (ctacte_pr_to_proveedor.tipo_iva_id == globals.zconf_tipo_iva_monotributo)
			T_neto_monotrib += neto_no_gravado_signo
		else
		{
			if (ctacte_pr_to_proveedor.tipo_iva_id == globals.zconf_tipo_iva_exento)
				T_neto_exento += neto_no_gravado_signo
			else
				T_neto_no_grav += neto_no_gravado_signo
		}
		if (neto != 0 && neto != null)
		{	
			var k = ctacte_pr_to_tasa_iva_porc.tasa_iva_id
				
			tabla_totales.setValue(k, 1, iva_porc)
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_signo)
		}
		
		if (neto_2 != 0 && neto_2 != null)
		{
			var k = ctacte_pr_to_tasa_iva_porc_2.tasa_iva_id;	
			tabla_totales.setValue(k, 1, iva_porc_2)			
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_2_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_2_signo)
		}
		if (neto_3 != 0 && neto_3 != null)
		{
			var k = ctacte_pr_to_tasa_iva_porc_3.tasa_iva_id;	
			tabla_totales.setValue(k, 1, iva_porc_3)			
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_3_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_3_signo)
		}
		lineas_hoja = 32 
		if (i%lineas_hoja == 0)
			saldo_aux = (i/lineas_hoja) + globals.ghoja_desde_diario
		if (i == $ctos && i%lineas_hoja != 0)
			saldo_aux = Math.floor(i/lineas_hoja) + globals.ghoja_desde_diario + 1
	}
	
	for ( var k = 1 ; k <= 10 ; k ++ )
	{
		if (tabla_totales.getValue(k, 1) != 0 && tabla_totales.getValue(k, 2) != 0 && tabla_totales.getValue(k, 3) != 0)	
		{
			f_iva_1 	= tabla_totales.getValue(1, 2)
			f_iva_2		= tabla_totales.getValue(2, 2)
			f_iva_3		= tabla_totales.getValue(3, 2)
			f_iva_4		= tabla_totales.getValue(4, 2)
			porc_1		= tabla_totales.getValue(1, 1)
			porc_2		= tabla_totales.getValue(2, 1)
			porc_3		= tabla_totales.getValue(3, 1)
			porc_4		= tabla_totales.getValue(4, 1)
			f_neto_1	= tabla_totales.getValue(1, 3)
			f_neto_2	= tabla_totales.getValue(2, 3)
			f_neto_3	= tabla_totales.getValue(3, 3)
			f_neto_4	= tabla_totales.getValue(4, 3)
		}   
	}
}
